/**
 * 	Copyright 2009 RJ Regenold 
 *	
 *	Licensed under the Apache License, Version 2.0 (the "License"); 
 *	you may not use this file except in compliance with the License. 
 *	You may obtain a copy of the License at 
 *	
 *		http://www.apache.org/licenses/LICENSE-2.0 
 *		
 *	Unless required by applicable law or agreed to in writing, software 
 *	distributed under the License is distributed on an "AS IS" BASIS, 
 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 *	See the License for the specific language governing permissions and 
 *	limitations under the License. 
 */

package com.binarylion.puremvc.patterns.facade {
	
	import com.binarylion.puremvc.core.FountController;
	import com.binarylion.puremvc.interfaces.IFountFacade;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import org.puremvc.as3.patterns.facade.Facade;
	
	public class FountFacade extends Facade implements IFountFacade {
		
		/**
		 * Default constructor.
		 */
		public function FountFacade() {
			super();
		}
		
		/**
		 * @inheritDoc
		 */
		public function rc(noteName:String, command:*):void {
		}
		
		// ------ IEventDispatcher implementation ------
		
		/**
		 * @inheritDoc
		 */
		public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void {
			dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
		}
		
		/**
		 * @inheritDoc
		 */
		public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void {
			dispatcher.removeEventListener(type, listener, useCapture);
		}
		
		/**
		 * @inheritDoc
		 */
		public function dispatchEvent(event:Event):Boolean {
			return dispatcher.dispatchEvent(event);
		}
		
		/**
		 * @inheritDoc
		 */
		public function hasEventListener(type:String):Boolean {
			return dispatcher.hasEventListener(type);
		}
		
		/**
		 * @inheritDoc
		 */
		public function willTrigger(type:String):Boolean {
			return dispatcher.willTrigger(type);
		}
		
		// ------ Protected members ------
		
		/** The event dispatcher. */
		protected var dispatcher:IEventDispatcher;
		
		/**
		 * @inheritDoc
		 */
		override protected function initializeFacade():void {
			super.initializeFacade();
			dispatcher = new EventDispatcher(this);			
		}
		
		/**
		 * @inheritDoc
		 */
		override protected function initializeController():void {
			if(controller) return;
			controller = FountController.getInstance();
		}
	}
}